Technical Q&As
QD 21 - Converting RGB Colors to a Palette Index (15-Sept-95)
Q How can I convert an RGB color into an index to a palette created by my
application? Color2Index converts the RGB color to an index to the current
device's color table, but that's not what I want.
A There's no single call that will give you a palette match to an RGB color.
You'll have to do this: call Color2Index to get the closest match to your RGB
request; call Index2Color to get the device's indexed color from your match;
search the palette yourself to find the color match (according to RGB value);
and call Color2Index to verify that you have the color you're looking for.
Alternatively, you can create an off-screen GWorld, call Palette2CTab to
convert your palette to a color table, and call UpdateGWorld to insert your new
color table in your off-screen GWorld. Then, to find the index of an RGB color,
make your GWorld the active device and call Color2Index.
Technical Q&As
Previous Question | Contents | Next Question